from multiprocessing.managers import BaseManager
from rest_framework import fields
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import ModelViewSet
from rest_framework.serializers import ModelSerializer
from ..models import Config


class ConfigSerializer(ModelSerializer):
    name = fields.CharField(required=False)

    class Meta:
        model = Config
        read_only_fields = ("user", "created_at", "modified_at")
        fields = "__all__"


class ConfigViewSet(ModelViewSet):
    queryset = Config.objects.all()
    serializer_class = ConfigSerializer
    # permission_classes = [IsAuthenticated]

    def get_queryset(self):
        print("get_queryset")
        # if self.request.user.is_authenticated:
        #     return Config.objects.filter(user=self.request.user)
        # return Config.objects.none()
        return Config.objects.all()

        # return [
        #     {
        #         "id": 1,
        #         "name": "Unnamed config (2025-05-21)",
        #         "content": "version: 3\nprofiles: []\nconfigSync:\n  parts: {}\nhotkeys:\n  settings:\n    - Ctrl-,\n  copy-current-path: []\n  ctrl-c:\n    - Ctrl-C\n  copy:\n    - Ctrl-Shift-C\n  paste:\n    - Ctrl-Shift-V\n    - Shift-Insert\n  select-all:\n    - Ctrl-Shift-A\n  clear: []\n  zoom-in:\n    - Ctrl-=\n    - Ctrl-Shift-=\n  zoom-out:\n    - Ctrl--\n    - Ctrl-Shift--\n  reset-zoom:\n    - Ctrl-0\n  home:\n    - Home\n  end:\n    - End\n  previous-word:\n    - Ctrl-Left\n  next-word:\n    - Ctrl-Right\n  delete-previous-word:\n    - Ctrl-Backspace\n  delete-next-word:\n    - Ctrl-Delete\n  search:\n    - Ctrl-Shift-F\n  pane-focus-all:\n    - Ctrl-Shift-I\n  restart-ssh-session: []\n  launch-winscp: []\n  serial:\n    - Alt-K\n  restart-serial-session: []\n  restart-telnet-session: []\n  profile: {}\n  profile-selectors: {}\n  toggle-fullscreen:\n    - F11\n    - Alt-Enter\n  close-tab:\n    - Ctrl-Shift-W\n  reopen-tab:\n    - Ctrl-Shift-T\n  toggle-last-tab: []\n  rename-tab:\n    - Ctrl-Shift-R\n  next-tab:\n    - Ctrl-Shift-Right\n    - Ctrl-Tab\n  previous-tab:\n    - Ctrl-Shift-Left\n    - Ctrl-Shift-Tab\n  move-tab-left:\n    - Ctrl-Shift-PageUp\n  move-tab-right:\n    - Ctrl-Shift-PageDown\n  rearrange-panes:\n    - Ctrl-Shift\n  duplicate-tab: []\n  tab-1:\n    - Alt-1\n  tab-2:\n    - Alt-2\n  tab-3:\n    - Alt-3\n  tab-4:\n    - Alt-4\n  tab-5:\n    - Alt-5\n  tab-6:\n    - Alt-6\n  tab-7:\n    - Alt-7\n  tab-8:\n    - Alt-8\n  tab-9:\n    - Alt-9\n  tab-10:\n    - Alt-0\n  tab-11: []\n  tab-12: []\n  tab-13: []\n  tab-14: []\n  tab-15: []\n  tab-16: []\n  tab-17: []\n  tab-18: []\n  tab-19: []\n  tab-20: []\n  split-right:\n    - Ctrl-Shift-E\n  split-bottom:\n    - Ctrl-Shift-D\n  split-left: []\n  split-top: []\n  pane-nav-right:\n    - Ctrl-Alt-Right\n  pane-nav-down:\n    - Ctrl-Alt-Down\n  pane-nav-up:\n    - Ctrl-Alt-Up\n  pane-nav-left:\n    - Ctrl-Alt-Left\n  pane-nav-previous:\n    - Ctrl-Alt-[\n  pane-nav-next:\n    - Ctrl-Alt-]\n  pane-maximize:\n    - Ctrl-Alt-Enter\n  close-pane: []\n  switch-profile:\n    - Ctrl-Alt-T\n  profile-selector:\n    - Ctrl-Shift-T\n  settings-tab: {}\n  delete-line:\n    - Ctrl-Shift-Backspace\n  focus-all-tabs:\n    - Ctrl-Alt-Shift-I\n  scroll-to-top:\n    - Ctrl-PageUp\n  scroll-up:\n    - Alt-PageUp\n  scroll-down:\n    - Alt-PageDown\n  scroll-to-bottom:\n    - Ctrl-PageDown\n  restart-tab: []\n  explode-tab:\n    - Ctrl-Shift-.\n  combine-tabs:\n    - Ctrl-Shift-,\n  pane-nav-1: []\n  pane-nav-2: []\n  pane-nav-3: []\n  pane-nav-4: []\n  pane-nav-5: []\n  pane-nav-6: []\n  pane-nav-7: []\n  pane-nav-8: []\n  pane-nav-9: []\n  pane-increase-vertical: []\n  pane-decrease-vertical: []\n  pane-increase-horizontal: []\n  pane-decrease-horizontal: []\n  command-selector:\n    - Ctrl-Shift-P\nterminal:\n  searchOptions: {}\n  colorScheme:\n    name: Material\n    foreground: '#eceff1'\n    background: rgba(38, 50, 56, 1)\n    selection: null\n    cursor: '#FFCC00'\n    cursorAccent: null\n    colors:\n      - '#000000'\n      - '#D62341'\n      - '#9ECE58'\n      - '#FAED70'\n      - '#396FE2'\n      - '#BB80B3'\n      - '#2DDAFD'\n      - '#d0d0d0'\n      - rgba(255, 255, 255, 0.2)\n      - '#FF5370'\n      - '#C3E88D'\n      - '#FFCB6B'\n      - '#82AAFF'\n      - '#C792EA'\n      - '#89DDFF'\n      - '#ffffff'\n  customColorSchemes: []\nssh:\n  knownHosts:\n    - host: 192.168.3.43\n      port: 22\n      type: ecdsa-sha2-nistp256\n      digest: OU+NBCz05A8Jmeta1/EQBwCgN5gJGIN1Qm5NqnPVbfA=\nweb: {}\nappearance: {}\npluginBlacklist:\n  - local\nprofileDefaults: {}\nelectronFlags:\n  - - force_discrete_gpu\n    - '0'\naccessibility: {}\nhacks: {}",
        #         "last_used_with_version": "1.0.197-nightly.1",
        #         "created_at": "2025-05-21T08:59:37.928356Z",
        #         "modified_at": "2025-05-26T08:43:55.111261Z",
        #         "user": 1
        #     }
        # ]

    def perform_create(self, serializer):
        serializer.save(user=self.request.user)
